package com.vehicle.convert;

import com.vehicle.domains.info.*;
import com.vehicle.domains.vo.Result;
import com.vehicle.domains.vo.req.zs.AlarmInfoPlateReq;
import com.vehicle.domains.vo.req.zs.ZsHeartBeatReq;
import com.vehicle.domains.vo.req.zs.ZsPlateDetectedReq;
import com.vehicle.domains.vo.req.zs.ZsSnapshotInReq;
import com.vehicle.domains.vo.res.zs.AlarmInfoPlate;
import com.vehicle.domains.vo.res.zs.AlarmInfoPlateRes;
import org.springframework.stereotype.Service;

@Service
public class ZsHttpConvert {
    public PlateDetectedInternalInfo parseZsPlateDetectedReq(ZsPlateDetectedReq req) {
        PlateDetectedInternalInfo plateDetectedInternalInfo = new PlateDetectedInternalInfo();
        InternalVehicleInfo internalVehicleInfo = new InternalVehicleInfo();
        AlarmInfoPlateReq.PlateResult plateResult = req.getAlarmInfoPlateReq().getResult().getPlateResult();
        internalVehicleInfo.setVehicleNumber(plateResult.getLicense());
        internalVehicleInfo.setPlateImgBase64(plateResult.getImageFragmentFile());
        internalVehicleInfo.setVehicleImgBase64(plateResult.getImageFile());

        InternalCameraInfo internalCameraInfo = new InternalCameraInfo();
        internalCameraInfo.setIp(req.getAlarmInfoPlateReq().getIpAddr());
        internalCameraInfo.setChannel(req.getAlarmInfoPlateReq().getChannel());

        plateDetectedInternalInfo.setInternalVehicleInfo(internalVehicleInfo);
        plateDetectedInternalInfo.setInternalCameraInfo(internalCameraInfo);

        return plateDetectedInternalInfo;
    }

    public HeartBeatInternalInfo parseZsHeartBeatReq(ZsHeartBeatReq req) {
        HeartBeatInternalInfo heartBeatInternalInfo = new HeartBeatInternalInfo();
        heartBeatInternalInfo.setIp(req.getIpaddr());
        return heartBeatInternalInfo;
    }

    public AlarmInfoPlateRes parseAlarmInfoPlate(boolean result, boolean snap) {
        AlarmInfoPlateRes alarmInfoPlateRes = new AlarmInfoPlateRes();
        AlarmInfoPlate alarmInfoPlate = new AlarmInfoPlate();
        alarmInfoPlate.setInfo(result ? "ok" : "error");
        if (snap) {
            AlarmInfoPlate.TriggerImage triggerImage = new AlarmInfoPlate.TriggerImage();
            triggerImage.setSnapImageRelativeUrl("/api/zs-camera/snapshot");
            alarmInfoPlate.setTriggerImage(triggerImage);
        }

        alarmInfoPlateRes.setAlarmInfoPlate(alarmInfoPlate);
        return alarmInfoPlateRes;
    }

    public SnapshotInternalInfo parseZsSnapshotInReq(ZsSnapshotInReq req) {
        SnapshotInternalInfo snapshotInternalInfo = new SnapshotInternalInfo();
        snapshotInternalInfo.setIp(req.getIpaddr());
        snapshotInternalInfo.setImageFile(req.getTriggerImage().getImageFile());
        return snapshotInternalInfo;
    }
}
